** This Do-File replicates Figure 1 and Figure A2 from P. Dutronc, A. Tondini  "Large Means-Tested Pensions with Informal Labor Markets" ** 

cd "" /*Input here directory where the appended data from the General Household Survey (2002-2015) is stored */ 

use "south_africa_GHS.dta", clear

keep if age>=50 & age<=70 /*Keep Age Window around the Thresholds of Eligibility to the Reforms*/ 

drop if year==2009 | year==2008 /*Exclude the years in which the reform was implemented */ 

gen post=(year>2008) /*1/0 variable for the after reform period */ 


* Create variable that includes both Pension and Disability grant * 
/* Note: the disability grant is alternative to the pension for people of younger age who are unable to work. 
It has the same means-test and pays the same amount, moreover it is automatically converted into the pension when one becomes age-eligibile. 
For this reason, when studying take-up between the age of 60-65, it makes sense to look at them jointly. Many disability grants are automatically
converted into old age pensions simply because the threshold is lowered. See text for explanation. */ 

gen oap=old_age
replace oap=1 if dis_grant==1


preserve 

collapse oap  [w=weight], by(age year sex post) /* Average within-year (with sample weights) */
collapse oap, by(age sex post) /* Average across years */

************
**Figure 1**
************

* Men * 

twoway (scatter oap age if post==0 & sex==1, msize(small) mcolor(black) ) || (line oap age if post==0 & sex==1, lcolor(black)) ///
|| (scatter oap age if post==1 & sex==1, msize(small) mcolor(black) ) || (line oap age if post==1 & sex==1, lcolor(black) lpattern(dash)) /// 
||, ytitle("OAP and Disability Grant")   xtitle("Age") graphregion( color(white) ) plotregion(  fcolor(white) ) legend(order (2 4) label(2 "Before Reform") label(4 "After Reform")) ylabel(0 (0.2) 1)

* Women * 


twoway (scatter oap age if post==0 & sex==2, msize(small) mcolor(black) ) || (line oap age if post==0 & sex==2, lcolor(black)) ///
|| (scatter oap age if post==1 & sex==2, msize(small) mcolor(black) ) || (line oap age if post==1 & sex==2, lcolor(black) lpattern(dash)) /// 
||, ytitle("OAP and Disability Grant")   xtitle("Age") graphregion( color(white) ) plotregion(  fcolor(white) ) legend(order (2 4) label(2 "Before Reform") label(4 "After Reform")) ylabel(0 (0.2) 1)

restore


keep if pop_group==1 | pop_group==2 /* Keep Black and Coloured individuals only, see text for explanation */ 

preserve 

collapse oap  [w=weight], by(age year sex post) /* Average within-year (with sample weights) */
collapse oap, by(age sex post) /* Average across years */

*************
**Figure A2**
*************

* Men * 

twoway (scatter oap age if post==0 & sex==1, msize(small) mcolor(black) ) || (line oap age if post==0 & sex==1, lcolor(black)) ///
|| (scatter oap age if post==1 & sex==1, msize(small) mcolor(black) ) || (line oap age if post==1 & sex==1, lcolor(black) lpattern(dash)) /// 
||, ytitle("OAP and Disability Grant")   xtitle("Age") graphregion( color(white) ) plotregion(  fcolor(white) ) legend(order (2 4) label(2 "Before Reform") label(4 "After Reform")) ylabel(0 (0.2) 1)

* Women * 


twoway (scatter oap age if post==0 & sex==2, msize(small) mcolor(black) ) || (line oap age if post==0 & sex==2, lcolor(black)) ///
|| (scatter oap age if post==1 & sex==2, msize(small) mcolor(black) ) || (line oap age if post==1 & sex==2, lcolor(black) lpattern(dash)) /// 
||, ytitle("OAP and Disability Grant")   xtitle("Age") graphregion( color(white) ) plotregion(  fcolor(white) ) legend(order (2 4) label(2 "Before Reform") label(4 "After Reform")) ylabel(0 (0.2) 1)

restore